package cn.tedu.tmall.admin.content.controller;

import cn.tedu.tmall.admin.content.pojo.param.CategoryAddNewParam;
import cn.tedu.tmall.admin.content.pojo.vo.CategoryStandardVO;
import cn.tedu.tmall.admin.content.service.ICategoryService;
import cn.tedu.tmall.common.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/categories")
@Api(tags = "1.类别管理")
@Validated
public class CategoryController {
    @Autowired
    private ICategoryService service;
    @PostMapping("/add-new")
    @ApiOperation("新增类别")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(@Validated CategoryAddNewParam categoryAddNewParam){
        service.addNew(categoryAddNewParam);
        return JsonResult.ok();
    }

    @ApiOperation("根据ID查询类别")
    @ApiOperationSupport(order = 410)
    @GetMapping("{id:[0-9]+}")
    @ApiImplicitParam(name="id",value = "类别ID",required = true,dataType = "long")
    public JsonResult getStandardById(@PathVariable @Range(min =1,message = "请提交有效的类别ID") Long id){
        final CategoryStandardVO standardById = service.getStandardById(id);
        return JsonResult.ok(standardById);
    }
}
